<?php
error_reporting(0);
include 'config.ini.php';

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>
        注册系统
    </title>
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="yes" name="apple-touch-fullscreen" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"
    />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="/login/cqlb/css/common_style.css">
    <link rel="stylesheet" href="/login/cqlb/css/h5_center.css">
    <script type="text/javascript" src="/login/cqlb/js/jquery.min.js">
    </script>
    <script type="text/javascript" src="/login/cqlb/js/h5_common.js">
    </script>
<audio autoplay="autoplay" loop=""><source src="/mp3/还是会想你.mp3"></audio>

   </audio>
</head>
	<style>
		h2 {
			margin-top: 100px;
			margin-bottom: -50px;
			text-align: center;
			color: #2E4045;
			text-shadow: 0 0 5px #ccc;
		}

		.login-page {
			width: 360px;
			padding-top: 8%;
			margin: auto;
		}
	</style>
<body class="full">
<div class="login-page">
<div id="acc" style="display:block">
<!--临时游戏背景图-->
<head>
<meta charset="utf-8">
<link href="css/koudai.css" type="text/css" rel="stylesheet"/>
</head>
<body  style="background-image: url(img/koudai.jpg); background-size: 100% ;background-attachment: fixed;" >
<body><img src="img/icon_logo.png" width="350"  /></body>
<!-- 账号登陆 -->
<!-- 手机登陆 -->
<div class="show_box popup_bg" id="mobile_login" style="display: block;">
    <div class="phone-login">
        <form id="frmLogin2" method="post" action="/index.php?act=reg" target="_top">
            <a href="javascript:;" class="closed_b" onclick="getzhlogin()">
                <img src="/login/cqlb/img/h5c_closed.png">
            </a>
            <span class="ltit">
                        账号注册
                    </span>
            <span class="inpt">
                        <input name="m_userName" id="m_userName" type="text" placeholder="请输入账号">
                    </span>
            <span class="inpt">
                        <input name="m_userPass" id="m_userPass" type="userPass" placeholder="请输入密码">
                    </span>
            <span class="inpt">
                        <input name="m_userPass2" id="m_userPass2" type="userPass" placeholder="请重复输入密码">
                    </span>
            <a href="javascript:;" class="login-btn" id="btnreg">
                注册
            </a>
        </form>
    </div>
</div>
<!-- 手机直接登陆 -->
</div>

<div id="game" style="display: none;width: 100%;height:99%;">
	<iframe id="ggg" src="" marginheight="0" marginwidth="0" style="width: 100%;height:99%;">
</iframe>
</div>
<script type="text/javascript">

var $_GET = (function(){
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if(typeof(u[1]) == "string"){
        u = u[1].split("&");
        var get = {};
        for(var i in u){
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        return get;
    } else {
        return {};
    }
})();


	/**
	 *检测获取获取Cookie账户密码
	 */


    /**
     * 已检测到账户并登陆
     */
    $("#btngo").click(function() {
	               $.post("/api.php?act=login", {
                    "userName": getCookie('user'),
                    "userPass": getCookie('pswd')
                },
                function(data) {
                    data = JSON.parse(data);
                    if (data.code < 1) {
                        alert(data.msg);
                    } else {
						document.getElementById("acc").style.display = 'none';
						document.getElementById("game").style.display = 'block';
						
						let url = "./api/game.php?";
						
						delete data['code'];
						delete data['msg'];
						
						for(let k in data){
							url += `${k}=${data[k]}&`;
						}
						window.location = url;
                    }
                });

    });

    function getzhlogin() {
        $(".show_box").hide();
        $("#user_login").show();
    }

    function getsjreg() {
        $(".show_box").hide();
        $("#mobile_login").show();
    }

    //登陆
    $("#btnlogin").click(function() {
        checkLoginForm();
    });
    //提交表单
    function checkLoginForm() {
        var lvUsername = $("#userName").val();
        var lvPWD = $("#userPass").val();
        if (lvUsername == "") {
            alert("请输入用户名！");
        } else if (lvUsername.length < 4) {
            alert("用户名长度不得小于4位！");
        } else if (!funcChina(lvUsername)) {
            alert("用户名不能含有汉字！");
        } else if (checkUserName(lvUsername)) {
            alert("用户名只能是字母和数字！");
        } else if (lvPWD == "" || lvPWD == "输入密码") {
            alert("输入密码！");
        } else if (lvPWD.length < 6) {
            alert("密码长度不得小于6位！");
        } else {
            $.post("/api.php?act=login", {
                    "userName": lvUsername,
                    "userPass": lvPWD
                },
                function(data) {
                    
                    data = JSON.parse(data);
                    if (data.code < 1) {
                        alert(data.msg);
                    } else {
						setCookie('user',lvUsername,365); 
						setCookie('pswd',lvPWD,365); 
						document.getElementById("acc").style.display = 'none';
						document.getElementById("game").style.display = 'block';
						let url = "./api/game.php?";
						
						delete data['code'];
						delete data['msg'];
						
						for(let k in data){
							url += `${k}=${data[k]}&`;
						}
						window.location = url;
						//document.getElementById("ggg").src = url;
                    }
                });
        }
    }

    /**
     * 注册并登录
     */
    $("#btnreg").click(function() {
        $("#type").val("1");
        checkRegForm();
    });
	var qd = "";//渠道
    function checkRegForm() {
        var lvUsername = $("#m_userName").val();
        var lvPWD = $("#m_userPass").val();
        var lvPWD2 = $("#m_userPass2").val();

        if (!lvPWD) {
            alert("请输入密码!");
            return false;
        } else if (lvPWD != lvPWD2) {
            alert("两次输入密码不同!");
            return false;
        } else if (lvUsername == lvPWD) {
            alert("帐号密码不能相同!");
            return false;
        } else if (lvUsername == "") {
            alert("请输入用户名！");
            return false;
        } else if (lvUsername.length < 4) {
            alert("用户名长度不得小于4位！");
        } else if (!funcChina(lvUsername)) {
            alert("用户名不能含有汉字！");
        } else if (checkUserName(lvUsername)) {
            alert("用户名只能是字母和数字！");
        } else if (lvPWD == "" || lvPWD == "输入密码") {
            alert("输入密码！");
        } else if (lvPWD.length < 6) {
            alert("密码长度不得小于6位！");
        } else {
            $.post("/api.php?act=reg", {
                    "userName": lvUsername,
                    "userPass": lvPWD,
                    "userPass1": lvPWD2,
					"qd": qd
                },
                function(data) {
                    data = JSON.parse(data);
                    if (data.code < 1) {
                        alert(data.msg);
                    } else {
						//保存账户密码到cookie
						setCookie('user',lvUsername,365); 
						setCookie('pswd',lvPWD,365);
						setCookie('qd',qd,365); 		
						document.getElementById("acc").style.display = 'none';
						document.getElementById("game").style.display = 'block';
						
						let url = "./api/game.php?";
						
						delete data['code'];
						delete data['msg'];
						
						for(let k in data){
							url += `${k}=${data[k]}&`;
						}
						window.location = url;
						//document.getElementById("ggg").src = url;
                    }
                });
        }
    }
	/**
	 * 设置cookie
	 */
  function setCookie(name,value,day){
    var date = new Date();
    date.setDate(date.getDate() + day);
    document.cookie = name + '=' + value + ';expires='+ date;
  };
  
  //获取cookie
  function getCookie(name){
    var reg = RegExp(name+'=([^;]+)');
    var arr = document.cookie.match(reg);
    if(arr){
      return arr[1];
    }else{
      return '';
    }
  };
  
  //删除cookie
  function delCookie(name){
    setCookie(name,null,-1);
  };
</script>
</body>
</html>